package org.nokatag.tagjava;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import org.nokatag.password.AESPlus;
import org.nokatag.system.Concest;

public class InputPass extends Inputsuper{

	private static final long serialVersionUID = 8790633944771551136L;
	private String veri = null;//验证
	private String chtype = null;//验证类型 chtype js|server|regex
	private String mesg = "erro mesages for input!";
	private String allownull="true";
	private String maxclass = null;//放大效果的class
	private String showpass = "false";//是否显示密码控制按钮
	private String onshowmax = null;
	
	public int doStartTag()throws JspException{
		JspWriter jspOut = pageContext.getOut();
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		String basePath = basepath(request);
		String pwidth = getWidth();
		pwidth =LenFormat((pwidth==null)?"120":pwidth);
		Integer iwidth = Integer.parseInt(LenNumber((pwidth==null)?"120":pwidth))+3;
		String ver = veri;
		FormHtmlInsertid(getId(),getName(),getValue());
		if("server".equals(chtype) && ver!=null && ver.trim().length()>0){
			ver ="verification:'"+ AESPlus.encrypt(ver, Concest.SQLKEY)+"'";//加密
		}else if("js".equals(chtype) && ver!=null && ver.trim().length()>0){
			ver ="verification:"+ ver;
		}else if("regex".equals(chtype) && ver!=null && ver.trim().length()>0){
			ver ="verification:'"+ver+"'";
		}else{
			ver ="verification:''";
		}
		NOOUT.put("width", true);
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append(potjs(request));//加载Prototype
		stringBuilder.append(inputTextJS(request));//加载Prototype
		stringBuilder.append("<div style=\"float: left;\">");
		stringBuilder.append("<div id=\""+getId()+"_maxDiv\" "+(maxclass==null?"":"class=\""+maxclass+"\"")+" style=\"position:absolute;-moz-border-radius:5px; border-radius:5px;\"></div>");//放大效果的div
		stringBuilder.append("<div id=\""+getId()+"_sdDiv\" class=\"nk_input_lineheight nk_input_sdDiv\" style=\"width:"+pwidth+";\">");
		stringBuilder.append("<div id=\""+getId()+"_intDiv\" style=\"float: left;border:0;padding:0px;margin:0px;\"><input  style=\"width:0px;height:0px;border:1px solid #ffffff;margin-left:-2px\"><input type=\"password\" class=\"nk_input_lineheight nk_input_text\" style=\"width:"+iwidth+"px\" ");
		stringBuilder.append(getBaseStr()+"/></div><div id=\""+getId()+"_chbut\" class=\"nk_input_lineheight\" style=\"float:right;border:0;padding:0px;margin:0px;\"></div></div>");
		if("false".equalsIgnoreCase(allownull)){
			stringBuilder.append("<div style=\"color: red;float: left;\" class=\"nk_input_lineheight\">*</div>");
		}
		stringBuilder.append("<img id=\""+getId()+"_img\" style=\"float: left;\" class=\"nk_input_imgheight\"/><div nowrap id=\""+getId()+"_div\" class=\"nk_input_message\" style=\"position:absolute;display:none;\">"+mesg+"</div>");
		stringBuilder.append("</div><div style=\"clear:both\"></div>");
		stringBuilder.append("<script type=\"text/javascript\">");
		stringBuilder.append("Event.observe(document, 'dom:loaded', function() {");
		stringBuilder.append("var cfgs"+getId()+" = {id:'"+getId()+"',chtype:'"+(chtype==null?"":chtype)+"',"+ver+",allownull:"+allownull+",rurl:'"+basePath+"'");
		if(null!=maxclass){
			stringBuilder.append(",maxclass:'"+maxclass+"'");
		}
		if(null!=onshowmax){
			stringBuilder.append(",onShowMax:function(a){return "+onshowmax+"(a);}");
		}
		if("true".equals(showpass)){
			stringBuilder.append(",showpass:true");
		}
		stringBuilder.append("};");
		stringBuilder.append("var np"+getId()+" = new ninput(cfgs"+getId()+");");
		stringBuilder.append("np"+getId()+".initinput();");
		stringBuilder.append("});");
		stringBuilder.append("</script>");
		
		try {
			jspOut.write(stringBuilder.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_BODY_INCLUDE;
	}
	public String getVeri() {
		return veri;
	}
	public void setVeri(String veri) {
		this.veri = veri;
	}
	public String getChtype() {
		return chtype;
	}
	public void setChtype(String chtype) {
		this.chtype = chtype;
	}
	public String getMesg() {
		return mesg;
	}
	public void setMesg(String mesg) {
		this.mesg = mesg;
	}
	public String getAllownull() {
		return allownull;
	}
	public void setAllownull(String allownull) {
		this.allownull = allownull;
	}
	public String getShowpass() {
		return showpass;
	}
	public void setShowpass(String showpass) {
		this.showpass = showpass;
	}
	public String getMaxclass() {
		return maxclass;
	}
	public void setMaxclass(String maxclass) {
		this.maxclass = maxclass;
	}
	public String getOnshowmax() {
		return onshowmax;
	}
	public void setOnshowmax(String onshowmax) {
		this.onshowmax = onshowmax;
	}
}

